home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / MUBBS_MO / EXAMPLE2 / SOME_TES.C < prev   
Text File  |  1991-11-14  |  3KB  |  113 lines

  1. /*
  2.  *  Some Tests.c
  3.  *
  4.  *    This program source code and it's compiled version is
  5.  *  Copyright (c) 1991 N. Hawthorn.
  6.  *  This program source code and it's compiled version IS NOT IN THE
  7.  *  PUBLIC DOMAIN ! Please read the "COPYRIGHT NOTICE / NH" file for details
  8.  *  regarding use of this program source code and it's compiled version.
  9.  *
  10.  *
  11.  * Some examples for you...
  12.  *
  13.  */
  14.  
  15. #include "MUBBS Module.h"
  16.  
  17. struct PPP {            /* this struct is NOT created here (globally) ! */
  18.             int hahaha; /* this is a test struct to pass some variables to the other */
  19.             int hehe;   /* test module */
  20.             };          /* you DONT HAVE TO USE THIS, just pass 0 to the module in P */
  21.                            /* and make this a empty struct */
  22.  
  23. tests(P)
  24. struct PPP *P;
  25. {
  26.  
  27. char datetime[25];
  28.  
  29. if (!G->online[u]) goto byebye; /* do this check so we can log out if hang up */
  30. print("This is the Example2 module, module mode is %d.\n",mode[u]);
  31. send("]Hello this is the Example2 module printing something to the user online]");
  32.  
  33. loop:
  34. if (P != 0L) /* only do this if we are passed a pointer to a something */
  35.     {
  36.     send("]P->hahaha=%d, P->hehe=%d IN THE MODULE !",P->hahaha,P->hehe);
  37.     P->hehe=100; /* change it to show that you can do this ! */
  38.     }
  39.  
  40. loguser(G->modulename[u]); /* this tells where you are for remote sysop, or writes to log file */
  41.  
  42. /* you print the following so that the sysop can monitor use on the mac screen */
  43.  
  44. print("C> Line %d %s, at: %s\n",(u+1),G->username[u],G->modulename[u]);
  45.  
  46. /* this print is for the Example module only */
  47.  
  48. print("\nC> This module's name is :%s, the calling module's name was :%s  ",G->modulename[u],G->oldmodulename[u]);
  49.  
  50. send("]]  *** Example2 Module Menu ***]]");
  51. if (!(cmd1(">> Getdatetime, Remove time, Sendafile, Time on, Quit :"))) goto byebye; /* timeout */
  52. send (G->CR[u]);
  53. switch (G->input[u]) {
  54.     case 'G':
  55.         getdatetime(datetime); /* gets the date & time */
  56.         send("]You are on line %d at %s PST]", (u+1), datetime);
  57.         break;
  58.     case 'R':
  59.         send("]Time WAS %d minutes so far, %d allowed]",G->timeon[u],G->timeallowed[u]);
  60.         if(G->timeallowed[u] > 5) { G->timeallowed[u]=5;} /* test the timeout in the menu module */
  61.         G->timeon[u]++;
  62.         send("]Time adjusted to %d minutes so far, %d allowed]",G->timeon[u],G->timeallowed[u]);
  63.         break;
  64.     case 'S':
  65.         send("]a test of open, sending \":testtext:test.txt\"]");
  66.         sendafile(":testtext:test.txt"); /* send this file in this folder */
  67.         break;
  68.     case 'T':
  69.         send("]You have been on line %d minutes so far, %d allowed]",G->timeon[u],G->timeallowed[u]);
  70.         break;
  71.     case 'Q':        /* Quit */
  72.         return;
  73.         break;
  74.     }
  75. if (!G->online[u]) goto byebye; /* log out */
  76. goto loop;
  77.  
  78. byebye:
  79. G->online[u]=FALSE; /* show we timed out */
  80. }
  81.  
  82.  
  83. sendafile(file) /* this shows you how file access works */
  84.                 /* this type of fuction is SUPPLIED to you in a call back */
  85.                 /* this is just for a EXAMPLE ! */
  86. char *file;
  87. {
  88. int i;
  89. unsigned char c;
  90. char temp[64];
  91. FILE *stream;
  92.  
  93. if ((stream = fopen(file, "r")) == NULL) {
  94.     print("\nFILE ERROR, cannot open %s ",file);
  95.     send("]FILE ERROR - Cannot open file %s ",file);
  96.     return;
  97.     }
  98. else print("\nopened %s ",file);
  99. strcpy(temp,"Viewing ");
  100. strcat(temp,file);
  101. loguser(temp);
  102. while (((i = fgetc(stream)) != EOF)) {
  103.     if (G->okcancel[u]) {if (G->cancel[u]) break;} /* check for cancel press */
  104.     c = i & 0xFF;
  105.     if ((c == 0x0A) || (c == 0x0D)) { send(G->CR[u]); }
  106.     else G->out(c);
  107.     }
  108. fclose(stream);
  109. G->cont[u]=FALSE; /* set for term line counting, incase they pressed "continuous" */
  110. }
  111.  
  112.  
  113.